from fastapi import APIRouter, Query,UploadFile
from tortoise.expressions import Q
from app.controllers.mini.comment import mini_comment_controller
from app.schemas.base import Success, SuccessExtra,Fail
from app.schemas.mini import *
from app.core.dependency import DependCustomerAuth
from app.core.ctx import CTX_USER_ID
mini_comment_router = APIRouter()
model_name = "评论"



@mini_comment_router.get("/list", summary=f"查看{model_name}列表", dependencies=[DependCustomerAuth])
async def do_mini_like_list(
        page: int = Query(1, description="页码"),
        page_size: int = Query(10, description="每页数量"),
        type: int = Query(1, description="类型"),
        type_id: int = Query(1, description="类型值"),
):
    q = Q(type=type)
    q &= Q(type_id=type_id)
    total, data = await mini_comment_controller.do_list(page=page, page_size=page_size, search=q)
    return SuccessExtra(data=data, total=total, page=page, page_size=page_size)


@mini_comment_router.post("/create", summary=f"创建{model_name}", dependencies=[DependCustomerAuth])
async def do_mini_like_create(
        data_in: MiniCommentCreate,
):
    user_id = CTX_USER_ID.get()
    data_in.user_id = user_id
    await mini_comment_controller.do_create(obj_in=data_in)
    return Success(msg="创建成功")


@mini_comment_router.get("/delete", summary=f"删除{model_name}", dependencies=[DependCustomerAuth])
async def do_mini_like_delete(
        data_id: int = Query(..., description="ID"),
):
    user_id = CTX_USER_ID.get()
    q = Q(user_id=user_id)
    q &= Q(id=data_id)
    await mini_comment_controller.do_delete(search=q)
    return Success(msg="删除成功")
